<?php
declare (strict_types = 1);

namespace app\command\test;

use app\command\BaseCommand;
use app\common\utils\MyLog;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;

/**
 * 命令行自定义指定示例
 * 参考: https://www.kancloud.cn/manual/thinkphp6_0/1037651
 */
class Test extends BaseCommand
{
    protected function configure()
    {
        // 指令配置
        $this->setName('Test')
            ->addArgument('type', Argument::REQUIRED, '类别')
            ->addArgument('name', Argument::OPTIONAL, '名称')
            ->setDescription('这是自定义命令行Test');
        $this->outputArgumentNotice();
    }

    protected function execute(Input $input, Output $output)
    {
        $all_args = $input->getArguments();
        P($all_args);

        $type = $input->getArgument('type');
        P($type);

        MyLog::record()->info($all_args, 'getArguments');
        MyLog::record()->info(['data'=>'OK'], '测试命令行写入一条log');

        // 指令输出
        $output->writeln('test output...');
    }
}
